/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IBlogDao;
import com.qiyou.dao.impl.BlogDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.Blog;
import com.qiyou.util.DBUtil;

/**
 * 博客数据操作代理
 * 
 * @author 赛艳志
 * 
 */
public class BlogDaoProxy implements IBlogDao {
    private Connection conn = null;
    private IBlogDao dao = null;

    public BlogDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new BlogDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Blog blog) throws SQLException {
        if (null != blog) {
            try {
                return dao.doCreate(blog);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doUpdate(Blog blog) throws SQLException {
        if (null != blog) {
            try {
                return dao.doUpdate(blog);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(long blogID) throws SQLException {
        if (blogID > 0) {
            try {
                return dao.doDelete(blogID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public Blog getBlog(long blogID) throws SQLException {
        if (blogID > 0) {
            try {
                return dao.getBlog(blogID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<Blog> getBlogs(String userID) throws SQLException {
        if (null != userID) {
            try {
                return dao.getBlogs(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<Blog> getBlogs(Object... params) throws SQLException {
        if (null != params) {
            try {
                return dao.getBlogs(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
